<?php
/**
 * 该类的主要作用是将session进行封装，并且做到需要的时候才会开启session,非常方便的工具
 * @author Administrator
 *
 */
class UserSessionTools{
	
	public function __construct(){
	}
	
	/*
	 * 从redis取得登录信息
	 */
	public function getUserSession($sessionId=0){
		global $redis,$cookieTools;
		if(!is_string($sessionId)){
			$userInfo = unserialize($redis->get($cookieTools->getCookie("sessionId")));
		}
		else {
			$userInfo = unserialize($redis->get($sessionId));
		}
		if(empty($userInfo))return false;
		else return $userInfo;
	}
	
	/**
	 * 效验登录信息是否存在
	 */
	public function validateLogin(){
		global $userSession,$cookieTools;
		$userInfo = $userSession->getUserSession($cookieTools->getCookie("sessionId"));
		
		if(empty($userInfo))
			return false;
		else
			return true;
	}
	
	/**
	 * 效验登录信息是否存在
	 */
	public function cancelLogin(){
		global $redis,$cookieTools;
		$redis->remove($cookieTools->getCookie("sessionId"));
	}
}
?>